<?php
/**
 * Created by PhpStorm.
 * User: HXL
 * Date: 2017/6/1
 * Time: 15:44
 */
namespace app\order\model;

use think\Db;

class Admins extends BaseModel{
    protected $tableName = 'ari_admins';

    /**
     * 模糊查询
     * @param $search
     * @param $tableName2
     * @param $param
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function searchLike($search){
        $count = Db::table($this->tableName)
            ->where('uid',  'like', "%$search%")->whereOr('username', 'like', "%$search%")->whereOr('surname', 'like', "%$search%")->count();
        $username = Db::table($this->tableName)
            ->where('uid',  'like', "%$search%")->whereOr('username', 'like', "%$search%")->whereOr('surname', 'like', "%$search%")
            ->paginate(10, $count, ['query' => request()->param()]);
        return $username;
    }

    /**
     * 带分页的联合查询
     * @param $where
     */
    public function joinPage($where, $order){
        $join = array(
            ['ari_roles role', $this->tableName.'.role_id = role.role_id'],
            ['ari_depts dept', $this->tableName.'.de_id = dept.de_id']
        );
        $count = $this->count($where);
        $joins = Db::table($this->tableName)->join($join)->where($where)->order($order)->paginate(10, $count, ['query' => request()->param()]);
        return $joins;
    }

    /**
     * 不带分页的联合查询
     * @param $where
     * @return false|\PDOStatement|string|\think\Collection
     */
    public function joinSelect($where){
        $join = array(
            ['ari_roles role', $this->tableName.'.role_id = role.role_id'],
            ['ari_depts dept', $this->tableName.'.de_id = dept.de_id']
        );
        $count = $this->count($where);
        $joins = Db::table($this->tableName)->join($join)->where($where)->select();
        return $joins;
    }

}